#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery
            , form = layui.form;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-120'    //容器高度
//            ,cellMinWidth: 30
            , cols: [[                  //标题栏
//                {checkbox: false,  fixed: true, space: true}
                {type: 'numbers', fixed: true, unresize: true}
                , {field: 'name', title: '名称', minWidth: 150,sort:true}
                , {field: 'responsibility', title: '职责', minWidth: 100,sort:true}
                , {field: 'detailedaddr', title: '地址', minWidth: 150,sort:true}
                , {field: 'superiorName', title: '上级部门', minWidth: 120, sort: true}
                , {field: 'principal', title: '上级负责人', width: 120,sort:true}
                , {field: 'principalcon', title: '负责人联系方式', width: 130,sort:true}
                , {field: 'manager', title: '部门主管', width: 100,sort:true}
                , {field: 'managercon', title: '主管联系方式', width: 130,sort:true}
                , {field: 'isEnable', title: '状态', width:80, sort: true,
                    templet: '#statusTpl(io.jboot.admin.service.entity.status.system.DataStatus::me(), "isEnable")' }
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barOption', minWidth: 160} //这里的toolbar值是模板元素的选择器
            ]]
            , url: '#(ctxPath)/system/organizationrole/managementTableData'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'unuse') {
                layer.confirm('确定禁用此组织?', function (index) {
                    util.sendAjax({
                        type: 'POST',
                        url: '#(ctxPath)/system/organizationrole/managementEnable',
                        data: {
                            id: data.id,
                            enable: false
                        },
                        loadFlag: true,
                        success: function (data) {
                            layer.close(index);
                            reloadTable($('#name').val(),$('#responsibility').val());
                        },
                        unSuccess: function (data) {
                            layer.close(index);
                        }
                    })
                });
            } else if (obj.event === 'use') {
                layer.confirm('确定启用此组织?', function (index) {
                    util.sendAjax({
                        type: 'POST',
                        url: '#(ctxPath)/system/organizationrole/managementEnable',
                        data: {
                            id: data.id,
                            enable: true
                        },
                        loadFlag: true,
                        success: function (data) {
                            layer.close(index);
                            reloadTable($('#name').val());
                        },
                        unSuccess: function (data) {
                            layer.close(index);
                        }
                    });
                });
            } else if (obj.event === 'pwd') {
                layer.confirm('是否确认为该组织改密?', function (index) {
                    pop_show('改密', '#(ctxPath)/system/organizationrole/changepwd?orgID=' + data.orgID, '400', '300', function () {
                        layer.close(index);
                    });
                });
            } else if(obj.event==="view"){
                pop_max_show('查看', '#(ctxPath)/system/organizationrole/view?orgID=' + data.orgID+"&type=management",function () {
                });
            }


        });


        reloadTable = function (_name,_responsibility, manager, isEnable) {
            table.reload('dateTable', {
                url: '#(ctxPath)/system/organizationrole/managementTableData'
                , where: {name: _name,responsibility:_responsibility, manager:manager, isEnable:isEnable} //设定异步数据接口的额外参数
            });
        };


        form.on('submit(search)', function (data) {
            reloadTable(data.field.name, data.field.responsibility, data.field.manager, data.field.isEnable);
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });


</script>
#end

#define content()
<div class="layui-fluid">
    <form id="searchForm" class="layui-form x-center" action="">
        <div class="layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">机构名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" placeholder="机构名称" class="layui-input"/>
                </div>
                <label class="layui-form-label">职责</label>
                <div class="layui-input-inline">
                    <input type="text" id="responsibility" name="responsibility" placeholder="职责" class="layui-input"/>
                </div>
                <label class="layui-form-label">主管</label>
                <div class="layui-input-inline">
                    <input type="text" id="manager" name="manager" placeholder="主管" class="layui-input"/>
                </div>
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select id="isEnable" name="isEnable">
                        <option value="1">启用</option>
                        <option value="0">禁用</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width : 80px">
                    <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </div>
    </form>
    <hr>
    <div class="layui-row">
        <!--<div class="layui-btn-group">-->
        <!--<button id="person" class="layui-btn layui-btn-small">个人审核</button>-->
        <!--<button id="organization" class="layui-btn layui-btn-small">团体审核</button>-->
        <!--</div>-->
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">

    #shiroHasPermission('/system/organizationrole/view')
    <a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
    #end


    #shiroHasPermission('/system/auth/view')
    #[[
    {{#  if(d.isEnable==true){ }}
    ]]#
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="unuse">锁定</a>

    #[[
    {{# } else{ }}
    ]]#
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="use">启用</a>
    #[[
    {{#  } }}
    ]]#
    #end

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="pwd">改密</a>
</script>
#end